package lime.dql.widget;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Text;

public class FileChooser extends Composite{

	// Widgets
	Text pathText;
	Button pathButton;
	
	String filePath;
	
	public FileChooser(Composite parent, int style, String filePath) {
		super(parent, style);
		this.filePath = filePath;
		init();
	}
	
	public void init() {
		
		this.setLayout(new GridLayout(2, false));
		
		pathText = new Text(this, SWT.BORDER);
		pathText.setText(filePath);
		pathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		pathButton = new Button(this, SWT.PUSH);
		pathButton.setText("Choose...");
		pathButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				FileDialog dialog = new FileDialog(pathButton.getShell(), SWT.SAVE);
				dialog.setFileName("export.xml");
				dialog.setFilterExtensions(new String[]{".xml"});
				String path = dialog.open();
				pathText.setText(path);
			}
		});
	}
	
	
	
	public String getFilePath() {
		return pathText.getText();
	}
}
